/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package controlepgto.util;

import java.text.ParseException;
import javax.swing.JFormattedTextField;
import javax.swing.JTextField;
import javax.swing.text.DefaultFormatterFactory;
import javax.swing.text.MaskFormatter;

/**
 *
 * @author Thiago
 */
public class MaskInsert {

    private static MaskFormatter mascara;

    public static void insertMask(String mask, String validChar, String invalidChar, JFormattedTextField fTextField) throws ParseException {

        if ( mask == null ) { return; }
        
        mascara = new MaskFormatter(mask);
        
        //Não vai considerar a mascara no binding.
        mascara.setValueContainsLiteralCharacters(false);
        
        if (validChar != null) {
            mascara.setValidCharacters(validChar);
        }
        if (invalidChar != null) {
            mascara.setInvalidCharacters(invalidChar);
        }    
        
        
        fTextField.setFormatterFactory(new DefaultFormatterFactory(mascara));

    }
    
    public static void SetaUpperCase(JTextField jtxt) {
        jtxt.setText(jtxt.getText().toUpperCase());
    }
    
    public static void SetaLowerCase(JTextField jtxt) {
        jtxt.setText(jtxt.getText().toLowerCase());
    }
}
